﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace skald_db
{
    public partial class frmAuth : Form
    {
        public frmAuth()
        {
            InitializeComponent();
        }
        private void frmAuth_Load(object sender, EventArgs e)
        {
        }
        private void btnCancel_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
 
        public static DialogResult PromptBox(string HEAD, string QUESTION, string CHECK1, string CHECK2, ref bool check1en, ref bool check2en, int NUMHECK, ref string value)
        {
 
            Form form = new Form();
            Button buttonOk = new System.Windows.Forms.Button();
            Button buttonCancel = new System.Windows.Forms.Button();
            Label label = new System.Windows.Forms.Label();
            TextBox textBox1 = new System.Windows.Forms.TextBox();
            CheckBox checkBox1 = new System.Windows.Forms.CheckBox();
            CheckBox checkBox2 = new System.Windows.Forms.CheckBox();

            buttonOk.Location = new System.Drawing.Point(12, 51);
            buttonOk.Name = "buttonOk";
            buttonOk.Size = new System.Drawing.Size(75, 23);
            buttonOk.TabIndex = 0;
            buttonOk.Text = "Ок";
            buttonOk.UseVisualStyleBackColor = true;
            // 
            // buttonCancel
            // 
            buttonCancel.Location = new System.Drawing.Point(255, 50);
            buttonCancel.Name = "buttonCancel";
            buttonCancel.Size = new System.Drawing.Size(75, 23);
            buttonCancel.TabIndex = 1;
            buttonCancel.Text = "Отмена";
            buttonCancel.UseVisualStyleBackColor = true;
            // 
            // label
            // 
            label.AutoSize = true;
            label.Location = new System.Drawing.Point(12, 9);
            label.Name = "label";
            label.Size = new System.Drawing.Size(35, 13);
            label.TabIndex = 2;
            label.Text = QUESTION;
            // 
            // textBox1
            // 
            textBox1.Location = new System.Drawing.Point(12, 25);
            textBox1.Name = "textBox1";
            textBox1.Size = new System.Drawing.Size(237, 20);
            textBox1.TabIndex = 3;
            // 
            // checkBox1
            // 
            if (NUMHECK >= 1)
            {
                checkBox1.AutoSize = true;
                checkBox1.Location = new System.Drawing.Point(255, 5);
                checkBox1.Name = "checkBox1";
                checkBox1.Size = new System.Drawing.Size(80, 17);
                checkBox1.TabIndex = 4;
                checkBox1.Text = CHECK1;
                checkBox1.UseVisualStyleBackColor = true;
            }
            // 
            // checkBox2
            // 
            if (NUMHECK >= 2)
            {
                checkBox2.AutoSize = true;
                checkBox2.Location = new System.Drawing.Point(255, 27);
                checkBox2.Name = "checkBox2";
                checkBox2.Size = new System.Drawing.Size(80, 17);
                checkBox2.TabIndex = 5;
                checkBox2.Text = CHECK2;
                checkBox2.UseVisualStyleBackColor = true;
            }
            // 
            // PromptBox
            //
            form.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            form.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            form.ClientSize = new System.Drawing.Size(347, 81);
            if (NUMHECK >= 2)
            {
                form.Controls.Add(checkBox2);
            }
            if (NUMHECK >= 1)
            {
                form.Controls.Add(checkBox1);
            }
            buttonOk.DialogResult = DialogResult.OK;
            buttonCancel.DialogResult = DialogResult.Cancel;
            form.StartPosition = FormStartPosition.CenterScreen;
            form.Controls.Add(textBox1);
            form.Controls.Add(label);
            form.Controls.Add(buttonCancel);
            form.Controls.Add(buttonOk);
            form.Name = "PromptBox";
            form.Text = HEAD;
            form.MinimizeBox = false;
            form.MaximizeBox = false;
            form.AcceptButton = buttonOk;
            form.CancelButton = buttonCancel;
            DialogResult dialogResult = form.ShowDialog();
            value = textBox1.Text;
            check1en = checkBox1.Checked;
            check2en = checkBox2.Checked;
            return dialogResult;
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            
            Authorisation Petuhi = new Authorisation();
            int UserRights = Petuhi.CheckUser(tbxUsername.Text, tbxPassword.Text);
            bool enter = false;
            switch (UserRights)
            {
                case 1:
                    Program.current_user_role = Program.roles.admin;
                    MessageBox.Show("Привет, Админ!");
                    enter = true;
                    break;
                case 2:
                    Program.current_user_role = Program.roles.man;
                    MessageBox.Show("Привет, менеджер!");
                    enter = true;
                    break;
                case 3:
                    Program.current_user_role = Program.roles.op;
                    MessageBox.Show("Привет, оператор!");
                    enter = true;
                    break;
                default:
                    MessageBox.Show("Неверный пара логин-пароль");
                    enter = false;
                    break;
            }
            if (enter) { 
                Form main_window =new frmMain() ;
                this.Hide();
                main_window.Show();
            }
        }
    }
}
